For anyone interested, I have finally managed to convert a simple SVG into a JPEG using Batik as part of a Java agent.
I tried using a string of XML as the SVG source, rather than a file, and this threw up some new error messages. It seems that the problem was related to the DOCTYPE definition in the sample files (supplied with Batik!).
The samples used this definition:
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 03December 1999//EN"
"
http://www.w3.org/Graphics/SVG/SVG-19991203.dtd">
But when I replaced it with the one listed on the SVG 1.1 recommendation on W3.org, it worked:
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"
http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
For the record, here is the successful agent code, which creates a JPEG version of a very simple SVG image. I imported all the Batik JAR files (plus the crimson parser) into the agent itself, and no longer have a 'JavaUserClasses' line in my notes.ini file:
import lotus.domino.*;
import java.io.*;
import org.apache.batik.transcoder.image.JPEGTranscoder;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
System.out.println(System.getProperty( "java.class.path" ));
String svgInput ="<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"
http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"><svg xml:space=\"preserve\" width=\"5.5in\" height=\"2in\"><rect style=\"fill:blue;\" width=\"250\" height=\"100\"/></svg>";
BufferedReader br = new BufferedReader(new StringReader(svgInput));
// create a JPEG transcoder
JPEGTranscoder t = new JPEGTranscoder();
// set the transcoding hints
t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
new Float(.8));
// create the transcoder output
OutputStream ostream = new FileOutputStream("C:\\Batik\\xml-batik\\samples\\out.jpg");
TranscoderOutput output = new TranscoderOutput(ostream);
// save the image
t.transcode(new TranscoderInput(br),output);
// flush and close the stream then exit
ostream.flush();
ostream.close();
System.exit(0);
} catch(Exception e) {
e.printStackTrace();
}
}
}